package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func producer(num int, out chan<- int) {
	out <- num * 2
	time.Sleep(time.Second * 2)
	wg.Done()
}

func consumer(in <-chan int) {
	for v := range in {
		fmt.Println("消费消息：", v)
		time.Sleep(time.Second)
	}
}

func main() {

	wg.Add(2)
	ch := make(chan int, 10)
	go producer(10, ch)
	go producer(5, ch)
	go consumer(ch)
	go consumer(ch)
	wg.Wait()
}
